﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace FatZombieAttack
{
    public class Zombie
    {

        private Vector2 ZombiePosition;
        private Texture2D ZombieImage;
        private int HealthPoints;
        SpriteFont Font;
        string HealthString;
        int size;
        int spawn;
        float MaxHealthPoints0 = 100;
        float MaxHealthPoints1 = 200;
        float MaxHealthPoints2 = 400;
        float Movespeed;
        float Movespeed0 = 50;
        float Movespeed1 = 45;
        float Movespeed2 = 40;
        
        public Zombie()
        {
            
        }
        public Zombie(int size1,int sp)
        {
            Movespeed = 50;
            size = size1;
            if (size == 0)
            { HealthPoints = (int)MaxHealthPoints0; }
            else if (size == 1)
            { HealthPoints = (int)MaxHealthPoints1; }
            else
            { HealthPoints = (int)MaxHealthPoints2; }
            spawn = sp;

        }
        public void Initialize()
        {
            HealthPoints = 100;
            AddZombieLocation(spawn);
        }
        public virtual void LoadContent(ContentManager Content)
        {
            AddZombieImage(Content);
            Font = Content.Load<SpriteFont>("Font/SpriteFont1");
            HealthString = HealthPoints.ToString();
        }
        public virtual void Update(GameTime gameTime,Player player)
        {
            HealthString = HealthPoints.ToString();
            Random random = new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0));
            if (HealthPoints <= 0)
            {
                if (size == 0)
                {
                    MaxHealthPoints0 = MaxHealthPoints0 * 1.2F;
                    HealthPoints = (int)MaxHealthPoints0;
                    SetSpawn(random.Next(0, 30));
                    AddZombieLocation(spawn);
                    Movespeed0 = Movespeed0 * 1.05F;
                    Movespeed = Movespeed0;
                    player.setplayerPoints(player.getplayerPoints() + 500);
                    
                }
                else if (size == 1)
                {
                    MaxHealthPoints1 = MaxHealthPoints1 * 1.5F;
                    SetSpawn(random.Next(10,30));
                    HealthPoints = (int)MaxHealthPoints1;
                    AddZombieLocation(spawn);
                    Movespeed1 = Movespeed1 * 1.1F;
                    Movespeed = Movespeed1;
                    player.setplayerPoints(player.getplayerPoints() + 1500);
                }
                else
                {
                    MaxHealthPoints2 = MaxHealthPoints2 * 1.8F;
                    HealthPoints = (int)MaxHealthPoints2;
                    SetSpawn(random.Next(10,30));
                    AddZombieLocation(spawn);
                    Movespeed2 = Movespeed2 * 1.1F;
                    Movespeed = Movespeed2;
                    player.setplayerPoints(player.getplayerPoints() + 4000);
                }
            }
            if (size == 0)
            {
                float distance = Vector2.Distance(new Vector2(player.getmidplayerPositionx(), player.getmidplayerPositiony()), new Vector2(ZombiePosition.X + 15, ZombiePosition.Y + 15));
                if (distance < 45)
                    player.setplayerHealthPoints(player.getplayerHealthPoints() - 1);
            }
            else if (size == 1)
            {
                float distance = Vector2.Distance(new Vector2(player.getmidplayerPositionx(), player.getmidplayerPositiony()), new Vector2(ZombiePosition.X + 30, ZombiePosition.Y + 30));
                if (distance < 60)
                    player.setplayerHealthPoints(player.getplayerHealthPoints() - 1);
            }
            else
            {
                float distance = Vector2.Distance(new Vector2(player.getmidplayerPositionx(), player.getmidplayerPositiony()), new Vector2(ZombiePosition.X + 40, ZombiePosition.Y + 40));
                if (distance < 80)
                    player.setplayerHealthPoints(player.getplayerHealthPoints() - 1);
            }

        }
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(ZombieImage, ZombiePosition, Color.White);
            if(size == 0)
                spriteBatch.DrawString(Font, HealthString, new Vector2(ZombiePosition.X, ZombiePosition.Y - 25), Color.White);
            else if (size== 1)
                spriteBatch.DrawString(Font, HealthString, new Vector2(ZombiePosition.X + 12, ZombiePosition.Y - 25), Color.White);
            else
                spriteBatch.DrawString(Font, HealthString, new Vector2(ZombiePosition.X + 20, ZombiePosition.Y - 25), Color.White);
        }
        public float GetHealthPoints() { return HealthPoints; }
        public void SetHealthPoints(int hp) { HealthPoints = hp; }
        public void SetSize(int s) { size = s;}
        public void SetMoveSpeed(float m) { Movespeed= m; }
        public float GetMoveSpeed() { return Movespeed; }
        public void SetSpawn(int s) { spawn = s; }
        public int GetSize() { return size; }
        public float getzombiePositionx() { return ZombiePosition.X; }
        public float getzombiePositiony() { return ZombiePosition.Y; }
        public void setzombiePositionx(float x) { ZombiePosition.X = x; }
        public void setzombiePositiony(float y) { ZombiePosition.Y = y; }
        public float getzombieSpeed() { return Movespeed; }
        public void setzombieSpeed(float x) { Movespeed = x; }

        public void AddZombieLocation(int s)
        {
            if (spawn == 0)
            {
                ZombiePosition = new Vector2(-300,500);
            }
            else if (spawn == 1)
            {
                ZombiePosition = new Vector2(400,1000); 
            }
            else if (spawn == 2)
            {
                ZombiePosition = new Vector2(1500,50);
            }
            else if (spawn == 3)
            {
                ZombiePosition = new Vector2(1000,-300);
            }
            else if (spawn == 4)
            {
                ZombiePosition = new Vector2(-600,0);
            }
            else if (spawn == 5)
            {
                ZombiePosition = new Vector2(-700,1200);
            }
            else if (spawn == 6)
            {
                ZombiePosition = new Vector2(1200,1200);
            }
            else if (spawn == 7)
            {
                ZombiePosition = new Vector2(1700,1100);
            }
            else if (spawn == 8)
            {
                ZombiePosition = new Vector2(1800,700);
            }
            else if (spawn == 9)
            {
                ZombiePosition = new Vector2(640,-750);
            }
            else if (spawn == 10)
            {
                ZombiePosition = new Vector2(-400,-750);
            }
            else if (spawn == 11)
            {
                ZombiePosition = new Vector2(-1280,375);
            }
            else if (spawn == 12)
            {
                ZombiePosition = new Vector2(640,1500);
            }
            else if (spawn == 13)
            {
                ZombiePosition = new Vector2(1800,-300);
            }
            else if (spawn == 14)
            {
                ZombiePosition = new Vector2(400,-1000);
            }
            else if (spawn == 15)
            {
                ZombiePosition = new Vector2(-700,-900);
            }
            else if (spawn == 16)
            {
                ZombiePosition = new Vector2(-800,1600);
            }
            else if (spawn == 17)
            {
                ZombiePosition = new Vector2(50,2000);
            }
            else if (spawn == 18)
            {
                ZombiePosition = new Vector2(2000,375);
            }
            else if (spawn == 19)
            {
                ZombiePosition = new Vector2(1800,-600);
            }
            else if (spawn == 20)
            {
                ZombiePosition = new Vector2(1500,-1000);
            }
            else if (spawn == 21)
            {
                ZombiePosition = new Vector2(-1280,-750);
            }
            else if (spawn == 22)
            {
                ZombiePosition = new Vector2(-50,2200);
            }
            else if (spawn == 23)
            {
                ZombiePosition = new Vector2(1100,2200);
            }
            else if (spawn == 24)
            {
                ZombiePosition = new Vector2(1800,2000);
            }
            else if (spawn == 25)
            {
                ZombiePosition = new Vector2(2000,1600);
            }
            else if (spawn == 26)
            {
                ZombiePosition = new Vector2(2200,750);
            }
            else if (spawn == 27)
            {
                ZombiePosition = new Vector2(2200,-100);
            }
            else if (spawn == 28)
            {
                ZombiePosition = new Vector2(1200,-1200);
            }
            else if (spawn == 29)
            {
                ZombiePosition = new Vector2(0,-1200);
            }
            else if (spawn == 30)
            {
                ZombiePosition = new Vector2(-700,-1200);
            }
            else if (spawn == 31)
            {
                ZombiePosition = new Vector2(-1600,-200);
            }
            else if (spawn == 32)
            {
                ZombiePosition = new Vector2(-1600,750);
            }
            else if (spawn == 33)
            {
                ZombiePosition = new Vector2(-1600,1600);
            }
            else if (spawn == 34)
            {
                ZombiePosition = new Vector2(2200,1100);
            }
            else if (spawn == 35)
            {
                ZombiePosition = new Vector2(2000,-1200);
            }
            else if (spawn == 36)
            {
                ZombiePosition = new Vector2(-1600,-1200);
            }
            else if (spawn == 37)
            {
                ZombiePosition = new Vector2(-900,2800);
            }
            else if (spawn == 38)
            {
                ZombiePosition = new Vector2(100,3000);
            }
            else if (spawn == 39)
            {
                ZombiePosition = new Vector2(1700,3000);
            }
            else if (spawn == 40)
            {
                ZombiePosition = new Vector2(2300,2500);
            }
            else if (spawn == 41)
            {
                ZombiePosition = new Vector2(2600,1500);
            }
            else if (spawn == 42)
            {
                ZombiePosition = new Vector2(2600,375);
            }
            else
            {
                ZombiePosition = new Vector2(2500,-750);
            } 
        }
        public void AddZombieImage(ContentManager Content)
        {

            if (size == 0)
            {
                ZombieImage = Content.Load<Texture2D>("Sprites/zombieSmall");
                HealthPoints = 100;              
            }
            else if (size == 1)
            {
                ZombieImage = Content.Load<Texture2D>("Sprites/zombieMedium");
                HealthPoints = 200;
            }
            else
            {
                ZombieImage = Content.Load<Texture2D>("Sprites/zombieLarge");
                HealthPoints = 400;
            }
        }
        
      

    }
}
